﻿using System;

namespace WiMo.Games
{
    public struct PointF
    {
        private Location _point;
        private float _x;
        private float _y;

        public PointF(float x, float y)
        {
            _x = x;
            _y = y;
            _point = new Location((int)x, (int)y);
        }

        public PointF(int x, int y)
        {
            _x = x;
            _y = y;
            _point = new Location((int)x, (int)y);
        }
        public float X
        {
            get { return _x; }
            set
            {
                _x = value;
                _point = new Location((int)value, (int)_y);
            }
        }

        public float Y
        {
            get { return _y; }
            set
            {
                _y = value;
                _point = new Location((int)_x, (int)value);
            }
        }

        /// <summary>
        /// Provides quick access to integer version of Point
        /// </summary>
        public Location Point
        {
            get { return _point; }
        }

        public static PointF operator +(PointF point, Vector2 vector)
        {
            point.X += vector.X;
            point.Y += vector.Y;

            return point;
        }

        public static bool operator == (PointF left, PointF right)
        {
            return (left.X == right.X && left.Y == right.Y);
        }

        public static bool operator != (PointF left, PointF right)
        {
            return !(left == right);
        }

        public static PointF operator +(PointF point1, PointF point2)
        {
            return new PointF(point1._x + point2._x, point1._y + point2._y);
        }

        public static PointF operator -(PointF point1, PointF point2)
        {
            return new PointF(point1._x - point2._x, point1._y - point2._y);
        }

        public static PointF operator +(PointF left, Size right)
        {
            return new PointF(left._x + right.Width, left._y + right.Height);
        }

        public static PointF operator -(PointF left, Size right)
        {
            return new PointF(left._x - right.Width, left._y - right.Height);
        }

        public PointF Clone()
        {
            return new PointF(X, Y);
        }

        public static PointF Origin
        {
            get { return new PointF(0, 0); }
        }


        public override int GetHashCode()
        {
            return Convert.ToInt32(_x * _y);
        }

        public override bool Equals(object obj)
        {
            if (typeof(PointF) != obj.GetType())
                return false;

            return this == (PointF)obj;
        }

        public override string ToString()
        {
            return string.Format(@"[{0:0000.0},{1:0000.0}]", _x, _y);
        }
    }
}
